#coding=utf-8
import random
import time
import os
from termcolor import colored
from colorama import init,Fore,Style # type: ignore

try:
    os.system('')  # 开启windows CMD的ANSI转义序列支持
    init(autoreset=True)
except:
    pass
print("\033[37m")
class Fill(str):
    def grey(st):
        return colored(st,"light_grey")
    def red(st):
        return colored(st,"red")
    def green(st):
        return colored(st,"green")
    def yellow(st):
        return colored(st,"yellow")
    def blue(st):
        return colored(st,"blue")
    def qing(st):
        return colored(st,"cyan")

skls= ["<R>哉佩利敖光线","<SR>须佐能乎",
       "<R>十万伏特","<R>焰分噬浪尺",
       "<SR>我眼即你眼","<SR>雷切",
       "<N>回复","<SR>无下限术式",
       "<R>超电磁炮","<SR>咒力拳"
       ]
skiwt=[1,  0.6,  
       1,  1,  
       0.6,  0.4,  
       0.9,  0.4,  
       1,  0.5  
       ]
tls=["<平凡>狂暴","<平凡>灵巧","<平凡>盾山","<平凡>铁腕"]
outls=[Fill.green("<平凡>狂暴"),Fill.green("<平凡>灵巧"),Fill.green("<平凡>盾山"),Fill.green("<平凡>铁腕")]
tlsid=[0,1,2,3]
tlwt=[1,1,1,1]
tlexps=["额外伤害","闪避概率增加","被暴击时部分伤害减免","额外生命值"]
xuzuoa=False
zaiyana=False
wuxiana=False
xuzuob=False
zaiyanb=False
wuxianb=False
zhoulia=-10
zhoulib=-10
tmpatka=0
tmpatkb=0

totalAttacka=0
totalAttackb=0
totalTreatmenta=0
totalTreatmentb=0
cnt=0
add=0
adda=0
addb=0
pointa=0
pointb=0
wina=0
winb=0
winner=0

#############################################定义随机函数
def doRandint(sd,bg,ed,c):

    random.seed(sd*c+time.time())
    return random.randint(bg,ed)

def doRandomChoice(sd,lst,c):

    random.seed(sd*c+time.time())
    return random.choice(lst)

def doRandomHide(sd,c):

    random.seed(sd*c+time.time())
    return random.randint(1,10)

def doUniqueRandom(sd,bg,ed):

    tmp=sd*sd-12
    random.seed(tmp)
    return random.randint(bg,ed)

def doRandomChoices(sd,lst,weights):

    random.seed(sd)
    return random.choices(lst,weights)[0]

def getRandomSeed(string,key):

    length=len(string)
    num=0
    for i in range(length):
        code=ord(string[i])*(i+1)
        num+=code*(key*2-1)
    return num


#############################################输入
print(Fill.red("================欢迎来到名字竞技场，战斗即将开始================"))
time.sleep(1)
nma=""
rda=0
nmb=""
rdb=0
nma=str(input("请输入名字1:  "))
rda=getRandomSeed(nma,1)
#print("<调试> "+nma+"的随机种子是："+str(rda))
nmb=str(input("请输入名字2:  "))
rdb=getRandomSeed(nmb,1)
#print("<调试> "+nmb+"的随机种子是："+str(rdb))

while True:
    totalRounds=int(input("请决定总场次："))
    if totalRounds<1:
        print(Fill.red("请输入正确的数字！"))
    elif totalRounds>100:
        print(Fill.red("这个数字太大了，请重新输入！"))
    else:
        break

#############################################各数值初始化处

print("战斗开始中，请稍等......")
time.sleep(1)

tlfa=doRandomChoices(rda,tlsid,tlwt)
tlfb=doRandomChoices(rdb,tlsid,tlwt)
print("===天赋初始化完成===")
time.sleep(0.5)
print(nma+"的天赋为： "+outls[tlfa])
time.sleep(0.1)
print("效果："+tlexps[tlfa])
time.sleep(0.5)
print(nmb+"的天赋为： "+outls[tlfb])
time.sleep(0.1)
print("效果："+tlexps[tlfb])
time.sleep(1)

lfa=doUniqueRandom(rda,100,200)
random.seed(rdb)
lfb=doUniqueRandom(rdb,100,200)
print("===血量初始化完成===")
if tlfa==3:
    adda=random.randint(10,30)
    print(nma+"的初始血量为： "+str(lfa)+"+"+str(adda))
    lfa+=adda
else:
    print(nma+"的初始血量为： "+str(lfa))
cstlfa=lfa

time.sleep(0.5)

if tlfb==3:
    addb=random.randint(10,30)
    print(nmb+"的初始血量为： "+str(lfb)+"+"+str(addb))
    lfb+=addb
else:
    print(nmb+"的初始血量为： "+str(lfb))
cstlfb=lfb

time.sleep(1)

print("")
print(Fill.red("==================战斗开始=================="))
print("")


#############################################主体
for rd in range(totalRounds):

    if wina>(totalRounds/2):
        print(" ")
        print(" ")
        print(" ")
        print(Fill.qing("==================最后"+nma+"胜利！！=================="))
        print("剩余血量："+str(lfa))
        break
    if winb>(totalRounds/2):
        print(" ")
        print(" ")
        print(" ")
        print(Fill.qing("==================最后"+nmb+"胜利！！=================="))
        print("剩余血量："+str(lfb))
        break
    print(Fill.qing("        =========第"+str(rd+1)+"场开始========="))
    print(nma+"获胜场次："+str(wina))
    print(nmb+"获胜场次："+str(winb))
    print("目前"+nma+"剩余点数："+str(pointa))
    print("目前"+nmb+"剩余点数："+str(pointb))
    lfa=cstlfa
    lfb=cstlfb

    for i in range(100):

        time.sleep(1)
        tmplfa=lfa
        tmplfb=lfb
        out=""

        #随机技能与攻击力
        skla=doRandomChoices(rda+time.time()+cnt,skls,skiwt)
        cnt+=1
        if (skla=="<SR>须佐能乎" and xuzuoa==True) or (skla=="<SR>我眼即你眼" and zaiyana==True) or (skla=="<SR>无下限术式" and zaiyana==True):
            while not(skla!="<SR>须佐能乎" and skla!="<SR>我眼即你眼" and skla!="<SR>无下限术式"):
                skla=doRandomChoices(rda+time.time()+cnt,skls,skiwt)
                cnt+=1

        atka=doRandint(rda,10,60,cnt)
        cnt+=1

        print(" ")
        print(Fill.qing("        =========第"+str(i+1)+"回合开始========="))

        #轮到A攻击的回合
        if skla=="<SR>须佐能乎":
            out=nma+"使用了"+Fill.blue(skla)+",下一次攻击必定暴击！"
            print(f"{out}")
            xuzuoa=True

        elif skla=="<SR>我眼即你眼":
            out=nma+"使用了"+Fill.blue(skla)+"给予了"+nmb+"一个致盲效果，他下回的攻击会被闪避！"
            print(f"{out}")
            zaiyana=True

        elif skla=="<N>回复":
            out=nma+"使用了"+Fill.green(skla)+"，恢复了"+str(atka)+"点血量"
            print(f"{out}")
            lfa+=atka
            totalTreatmenta+=atka

        elif skla=="<SR>无下限术式":
            out=nma+"使用了"+Fill.blue(skla)+"，下回"+nmb+"的攻对他无效！"
            print(f"{out}")
            wuxiana=True

        elif skla=="<SR>雷切":
            wuxianb=False
            zaiyanb=False
            if tlfa==0:
                out=nma+"使用了"+Fill.blue(skla)+"，无视"+nmb+"的天赋，无法减伤或躲避!"+"打出了"+str(atka)+"+"+str(add)+"点伤害"
                print(f"{out}")
                add=doRandint(rda,1,10,time.time())
                atka+=add
            else:
                out=nma+"使用了"+Fill.blue(skla)+"，无视"+nmb+"的天赋，无法减伤或躲避!"+"打出了"+str(atka)+"点伤害"
                print(f"{out}")
            lfb-=atka
            print(nmb+"受到了"+str(atka)+"点伤害")

        else:
            if tlfa==0:
                add=doRandint(rda,1,10,time.time())
                if skla=="<SR>咒力拳":
                    print(nma+"使用了"+Fill.blue(skla)+"，打出了"+str(atka)+"+"+str(add)+"点伤害")
                else:
                    print(nma+"使用了"+Fill.green(skla)+"，打出了"+str(atka)+"+"+str(add)+"点伤害")
                atka+=add
            else:
                if skla=="<SR>咒力拳":
                    print(nma+"使用了"+Fill.blue(skla)+"，打出了"+str(atka)+"点伤害")
                else:
                    print(nma+"使用了"+Fill.green(skla)+"，打出了"+str(atka)+"点伤害")

            time.sleep(0.5)
            hdb=doRandomHide(rdb,cnt)
            cnt+=1

            if xuzuoa:
                if tlfb==2:
                    add=doRandint(rdb,5,20,time.time())
                    out="由于"+nma+"使用了<SR>须佐能乎，"+nmb+"直接受到了暴击，承受了"+str(atka*2)+"-"+str(add)+"点伤害"
                    print(f"{out}")
                    lfb-=atka*2+add
                else:
                    out="由于"+nma+"使用了<SR>须佐能乎，"+nmb+"直接受到了暴击，承受了"+str(atka*2)+"点伤害"
                    print(f"{out}")
                    lfb-=atka*2
                xuzuoa=False

            elif zaiyanb:
                out="由于"+nmb+"使用了<SR>我眼即你眼，"+nmb+"闪避成功，只承受了"+str(atka/2)+"点伤害"
                print(f"{out}")
                lfb-=atka/2
                zaiyanb=False

            elif wuxianb:
                print("但是由于"+nmb+"使用了<SR>无下限术式，所以本次攻击不奏效！")
                wuxianb=False

            else:
                nbrdm=doRandint(time.time(),1,15,cnt)
                cnt+=1
                if nbrdm==7:
                    out=nmb+"直接反弹，使"+nma+"受到了"+str(atka-10)+"点伤害！"
                    lfa-=atka-10
                    print(Fill.qing(out))

                elif 1<=rdb and 3>=rdb:
                    tri=random.randint(1,5)
                    if tlfb==1 and tri==3:
                        out=nmb+"灵巧地躲过了暴击，只承受了"+str(atka)+"点伤害"
                        print(Fill.grey(out))
                        lfb-=atka
                    else:
                        if tlfb==2:
                            add=doRandint(rdb,5,20,time.time())
                            out=nmb+"躲闪不及，受到了暴击，承受了"+str(atka*2)+"-"+str(add)+"点伤害"
                            print(Fill.red(out))
                            lfb-=atka*2+add
                        else:
                            out=nmb+"躲闪不及，受到了暴击，承受了"+str(atka*2)+"点伤害"
                            print(Fill.red(out))
                            lfb-=atka*2

                elif 8<=rdb and 10>=rdb:
                    out=nmb+"闪避成功，只承受了"+str(atka/2)+"点伤害"
                    print(Fill.grey(out))
                    lfb-=atka/2

                else:
                    tri=random.randint(1,5)
                    if tlfb==1 and tri==3:
                        out=nmb+"灵巧地躲过了攻击，只承受了"+str(atka/2)+"点伤害"
                        print(Fill.grey(out))
                        lfb-=atka/2
                    else:
                        print(nmb+"受到了"+str(atka)+"点伤害")
                        lfb-=atka

        time.sleep(1)

        #统计数据
        if(tmplfb-lfb>0):
            totalAttacka+=tmplfb-lfb
        if(tmplfa-lfa>0):
            totalAttackb+=tmplfa-lfa

        #判断是否有一方倒下
        if(lfa<=0):
            print(" ")
            print(" ")
            print(" ")
            print(Fill.yellow("=================="+str(rd+1)+"场结束，"+nmb+"胜利！！=================="))
            print("剩余血量："+str(lfb))
            print(" ")
            print(" ")
            print(" ")
            break
        if(lfb<=0):
            print(" ")
            print(" ")
            print(" ")
            print(Fill.yellow("=================="+str(rd+1)+"场结束，"+nma+"胜利！！=================="))
            print("剩余血量："+str(lfa))
            print(" ")
            print(" ")
            print(" ")
            break

        #随机技能与攻击力
        sklb=doRandomChoices(rdb+time.time()+cnt,skls,skiwt)
        cnt+=1
        if (sklb=="<SR>须佐能乎" and xuzuob==True) or (sklb=="<SR>我眼即你眼" and zaiyanb==True) or (sklb=="<SR>无下限术式" and zaiyanb==True):
            while not(sklb!="<SR>须佐能乎" and sklb!="<SR>我眼即你眼" and sklb!="<SR>无下限术式"):
                sklb=doRandomChoices(rdb+time.time()+cnt,skls,skiwt)
                cnt+=1

        atkb=doRandint(rdb,10,60,cnt)
        cnt+=1

        #轮到B攻击的回合    
        if sklb=="<SR>须佐能乎":
            out=nmb+"使用了"+Fill.blue(sklb)+"，下一次攻击必定暴击！"
            print(f"{out}")
            xuzuob=True

        elif sklb=="<SR>我眼即你眼":
            out=nmb+"使用了"+Fill.blue(sklb)+"，给予了"+nma+"一个致盲效果，他下回的攻击会被闪避！"
            print(f"{out}")
            zaiyanb=True

        elif sklb=="<N>回复":
            out=nmb+"使用了"+Fill.green(sklb)+"，恢复了"+str(atkb)+"点血量"
            print(f"{out}")
            lfb+=atkb
            totalTreatmentb+=atkb

        elif sklb=="<SR>无下限术式":
            out=nmb+"使用了"+Fill.blue(sklb)+"，下回"+nma+"的攻对他无效！"
            print(f"{out}")
            wuxianb=True

        elif sklb=="<SR>雷切":
            wuxiana=False
            zaiyana=False
            if tlfb==0:
                out=nmb+"使用了"+Fill.blue(sklb)+"，无视"+nma+"的任何天赋与防御，无法减伤或躲避!"+"打出了"+str(atkb)+"+"+str(add)+"点伤害"
                print(f"{out}")
                add=doRandint(rdb,1,10,time.time())
                atkb+=add
            else:
                out=nmb+"使用了"+Fill.blue(sklb)+"，无视"+nma+"的任何天赋与防御，无法减伤或躲避!"+"打出了"+str(atkb)+"点伤害"
                print(f"{out}")
            lfa-=atkb
            print(nma+"受到了"+str(atkb)+"点伤害")

        else:
            if tlfb==0:
                add=doRandint(rdb,1,10,time.time())
                if sklb=="<SR>咒力拳":
                    print(nmb+"使用了"+Fill.blue(sklb)+"，打出了"+str(atkb)+"+"+str(add)+"点伤害")
                else:
                    print(nmb+"使用了"+Fill.green(sklb)+"，打出了"+str(atkb)+"+"+str(add)+"点伤害")
                atkb+=add
            else:
                if sklb=="<SR>咒力拳":
                    print(nmb+"使用了"+Fill.blue(sklb)+"，打出了"+str(atkb)+"点伤害")
                else:
                    print(nmb+"使用了"+Fill.green(sklb)+"，打出了"+str(atkb)+"点伤害")

            time.sleep(0.5)
            hda=doRandomHide(rda,cnt)
            cnt+=1

            if xuzuob:
                if tlfa==2:
                    add=doRandint(rdb,5,20,time.time())
                    out="由于"+nmb+"使用了<SR>须佐能乎，"+nma+"直接受到了暴击，承受了"+str(atkb*2)+"-"+str(add)+"点伤害"
                    print(f"{out}")
                    lfa-=atkb*2+add
                else:
                    out="由于"+nmb+"使用了<SR>须佐能乎，"+nma+"直接受到了暴击，承受了"+str(atkb*2)+"点伤害"
                    print(f"{out}")
                    lfa-=atkb*2

                xuzuob=False

            elif zaiyana:
                out="由于"+nma+"使用了<SR>我眼即你眼，"+nma+"闪避成功，只承受了"+str(atkb/2)+"点伤害"
                print(f"{out}")
                lfa-=atkb/2
                zaiyana=False

            elif wuxiana:
                print("但是由于"+nma+"使用了<SR>无下限术式，所以本次攻击不奏效！")
                wuxiana=False

            else:
                nbrdm=doRandint(time.time(),1,15,cnt)
                cnt+=7
                if nbrdm==20:
                    out=nma+"直接反弹，使"+nmb+"受到了"+str(atkb-10)+"点伤害！"
                    lfb-=atkb-10
                    print(Fill.qing(out))

                elif 1<=rda and 3>=rda:
                    tri=random.randint(1,5)
                    if tlfa==1 and tri==3:
                        out=nma+"灵巧地躲过了暴击，只承受了"+str(atkb)+"点伤害"
                        print(Fill.grey(out))
                        lfa-=atkb
                    else:

                        if tlfa==2:
                            add=doRandint(rda,5,20,time.time())
                            out=nma+"躲闪不及，受到了暴击，承受了"+str(atkb*2)+"-"+str(add)+"点伤害"
                            print(Fill.red(out))
                            lfa-=atkb*2+add
                        else:
                            out=nma+"躲闪不及，受到了暴击，承受了"+str(atkb*2)+"点伤害"
                            print(Fill.red(out))
                            lfa-=atkb*2

                elif 7<=rda and 10>=rda:
                    out=nma+"闪避成功，只承受了"+str(atkb/2)+"点伤害"
                    print(Fill.grey(out))
                    lfa-=atkb/2

                else:
                    tri=random.randint(1,5)
                    if tlfa==1 and tri==3:
                        out=nma+"灵巧地躲过了攻击，只承受了"+str(atkb/2)+"点伤害"
                        print(Fill.grey(out))
                        lfa-=atkb/2
                    else:
                        print(nma+"受到了"+str(atkb)+"点伤害")
                        lfa-=atkb

        time.sleep(1)

        #事件触发判定
        if((i+1)%5==0): #恩赐
            add=doRandint(time.time(),20,50,cnt)
            cnt+=1
            nid=doRandint(time.time(),0,1,cnt)
            cnt+=1
            if bool(nid):
                print("本回合触发了"+Fill.green("天使的恩赐,")+nma+"血量回复"+str(add)+"点")
                lfa+=add
            else:
                print("本回合触发了"+Fill.green("天使的恩赐,")+nmb+"血量回复"+str(add)+"点")
                lfb+=add

        if((i+1)%7==0): #诅咒
            add=doRandint(time.time(),20,50,cnt)
            cnt+=1
            nid=doRandint(time.time(),0,1,cnt)
            cnt+=1
            if bool(nid):
                print("本回合触发了"+Fill.red("恶魔的诅咒,")+nma+"血量扣除"+str(add)+"点")
                lfa-=add
            else:
                print("本回合触发了"+Fill.red("恶魔的诅咒,")+nmb+"血量扣除"+str(add)+"点")
                lfb-=add

        if skla=="<SR>咒力拳":
                zhoulia=i+1
                tmpatka=atka
        if sklb=="<SR>咒力拳":
                zhoulib=i+1
                tmpatkb=atkb
        if zhoulia==i:
            print(nmb+"受到"+nma+"的延迟咒力伤害"+str(int(tmpatka*1.2))+"点")
            lfb-=int(tmpatka*1.2)
        if zhoulib==i:
            print(nma+"受到"+nmb+"的延迟咒力伤害"+str(int(tmpatkb*1.2))+"点")
            lfa-=int(tmpatkb*1.2)
        #结算本回合
        print(Fill.qing("        =========第"+str(i+1)+"回合结束========="))
        print(" ")

        #判断是否有一方倒下
        if(lfa<=0):
            print(" ")
            print(" ")
            print(" ")
            out="=================="+str(rd+1)+"场结束，"+nmb+"胜利！！=================="
            print(Fill.yellow(out))
            print("                  剩余血量："+str(lfb))
            print(" ")
            print(" ")
            print(" ")
            break

        if(lfb<=0):
            print(" ")
            print(" ")
            print(" ")
            out="=================="+str(rd+1)+"场结束，"+nma+"胜利！！=================="
            print(Fill.yellow(out))
            print("                  剩余血量："+str(lfa))
            print(" ")
            print(" ")
            print(" ")
            break
        
        #统计数据
        if(tmplfb-lfb>0):
            totalAttacka+=tmplfb-lfb
        if(tmplfa-lfa>0):
            totalAttackb+=tmplfa-lfa
        time.sleep(0.5)
        print(nma+"剩余血量："+str(lfa))
        print(nmb+"剩余血量："+str(lfb))



#############################################结算画面
print(Fill.qing("==================结算中=================="))
print(" ")
time.sleep(2)
print(nma+"总治疗量："+str(totalTreatmenta))
print(nmb+"总治疗量："+str(totalTreatmentb))
print(nma+"总受到伤害："+str(totalAttackb))
print(nmb+"总受到伤害："+str(totalAttacka))
print("总回合数:"+str(i+1))
print(" ")
os.system('pause')